﻿/********************************************************************************
Function:  its_RepProblem_InsertUpdateDeleteDisp
Description:
     its_RepProblem() 新增/修改/删除/显示
Author:
     DDBuildTools                                      
     http://DDBuildTools.supesoft.com
Finish DateTime:
     2011-10-15 22:58:27
Return Value:
     -1:存储过程执行失败
     -2:存在相同的主键
     Insert:返回插入自动ID
     Update:返回更新记录数
     Delete:返回删除记录数                           
*********************************************************************************/
CREATE PROCEDURE its_RepProblem_InsertUpdateDelete
(	
    
        @ID	 int = 0,	-- 
        @ServRepProb	 int = 0,	-- 通用报修问题
        @Context	 varchar(500) = '',	-- 问题描述
        @ServTrobTypeId	 int = 0,	-- 问题分类
        @ServProbTypeId	 int = 0,	-- 故障分类
        @ResolventId	 int = 0,	-- 通用解决方法	
	@DataTable_Action_  varchar(10) = ''		-- 操作方法 Insert:增加 Update:修改 Delete:删除 
)
AS
	
	DECLARE @ReturnValue varchar(18) -- 返回操作结果	
	
	SET @ReturnValue = -1
	
	-- 新增
	IF (@DataTable_Action_='Insert')
	BEGIN
		INSERT INTO dbo.its_RepProblem( 
        
                    ServRepProb,
                    Context,
                    ServTrobTypeId,
                    ServProbTypeId,
                    ResolventId
		) VALUES (	
        
                    @ServRepProb,
                    @Context,
                    @ServTrobTypeId,
                    @ServProbTypeId,
                    @ResolventId
		)
		SELECT @ReturnValue = SCOPE_IDENTITY()
	END
	
	-- 更新
	IF (@DataTable_Action_='Update')
	BEGIN
		UPDATE dbo.its_RepProblem SET	
        
                    ServRepProb=@ServRepProb,
                    Context=@Context,
                    ServTrobTypeId=@ServTrobTypeId,
                    ServProbTypeId=@ServProbTypeId,
                    ResolventId=@ResolventId
		WHERE (ID=@ID)
		
		SELECT @ReturnValue = @@ROWCOUNT
	END
	
	-- 删除
	IF (@DataTable_Action_='Delete')
	BEGIN
		DELETE dbo.its_RepProblem	WHERE (ID=@ID)
		SET @ReturnValue = @@ROWCOUNT
  	END

SELECT @ReturnValue
GO
